package com.duan.laugh.email.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.duan.laugh.common.core.util.Query;
import com.duan.laugh.common.core.util.R;
import com.duan.laugh.email.api.pojo.entity.EmailAccount;
import com.duan.laugh.email.service.IEmailAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 邮件账户 controller
 * </p>
 *
 * @author liutf
 * @since 2019-11-07
 */
@Api(tags = "邮件账户")
@RestController
@RequestMapping("/email-account")
public class EmailAccountController {
    @Autowired
    private IEmailAccountService emailAccountService;

    /**
     * 新增邮件账户
     *
     * @param emailAccount 实体
     * @return true/false
     */
    @PostMapping
    @ApiOperation("新增邮件账户")
    public R save(@RequestBody EmailAccount emailAccount) {
        return R.ok(emailAccountService.save(emailAccount));
    }

    /**
     * 根据id查看邮件账户
     *
     * @param id
     * @return EmailAccount
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查看邮件账户")
    public R<EmailAccount> getById(@PathVariable String id) {
        return R.ok(emailAccountService.getById(id));
    }

    /**
     * 分页查询邮件账户
     *
     * @param params 分页对象
     * @return 分页对象
     */
    @PostMapping("/page")
    @ApiOperation("分页查询邮件账户")
    public IPage<EmailAccount> page(@RequestBody Map<String, Object> params) {
        return emailAccountService.page(new Query<>(params));
    }

    /**
     * 根据id删除邮件账户
     *
     * @param id
     * @return true/false
     */
    @DeleteMapping("/{id}")
    @ApiOperation("根据id删除邮件账户")
    public R removeById(@PathVariable String id) {
        return R.ok(emailAccountService.removeById(id));
    }

    /**
     * 根据id修改邮件账户
     *
     * @param emailAccount 实体
     * @return true/false
     */
    @PutMapping
    @ApiOperation("根据id修改邮件账户")
    public R updateById(@RequestBody EmailAccount emailAccount) {
        return R.ok(emailAccountService.updateById(emailAccount));
    }

}

